package com.itboye.ihomebank.adapter;

import java.util.List;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.base.NavigationBean;
import com.itboye.ihomebank.util.PhoneUtil;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

/***
 * 导航Adapter
 * @author admin
 *
 */
public class NavigationAdapter extends BaseAdapter {
	List<NavigationBean> dataList;
	Activity activity;
	public NavigationAdapter(List<NavigationBean> dataList,Activity activity) {
		this.dataList=dataList;
		this.activity=activity;
	}

	@Override
	public int getCount() {
		
		return dataList==null?0:dataList.size();
	}

	@Override
	public Object getItem(int position) {
		
		return dataList==null?0:dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView==null) {
			convertView=LayoutInflater.from(MyApplcation.ctx.ctx).inflate(R.layout.item_navigation, null);
			holder=new ViewHolder();
			holder.destination=(TextView) convertView.findViewById(R.id.destination);//目的地
			holder.detail_addr=(TextView) convertView.findViewById(R.id.detail_addr);//详细地址
			holder.re_go_there=(RelativeLayout) convertView.findViewById(R.id.re_go_there);
			holder.re_panorama=(RelativeLayout) convertView.findViewById(R.id.re_panorama);
			holder.re_phone=(RelativeLayout) convertView.findViewById(R.id.re_phone);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		holder.destination.setText(dataList.get(position).getName());//目的地
		holder.detail_addr.setText(dataList.get(position).getAddressDetail());//详细地址
		holder.re_phone.setTag(position);
		holder.re_phone.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
					PhoneUtil.goTel(dataList.get((int) v.getTag()).getTelephone(), activity);
			}
		});
		holder.re_go_there.setTag(position);
		holder.re_go_there.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				Intent intent=new Intent(activity,BNDemoMainActivity.class);
//				intent.putExtra("lng", "120.377398");
//				intent.putExtra("lat", "30.316951");
//				activity.startActivity(intent);
			}
		});
		return convertView;
	}

	class ViewHolder{
		TextView destination;
		TextView detail_addr;
		RelativeLayout re_go_there;//到这里去
		RelativeLayout re_panorama;//全景
		RelativeLayout re_phone;//电话
	}
}
